/*
 *  $Id: Berserk.cs 975 2009-12-16 17:13:22Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Affects {
    /// <summary>
    /// Эффект: берсерк (флаг)
    /// Существо всегда идет в атаку.
    /// </summary>
    public class Berserk: FlagAffect {
        public override string Id {
            get { return "berserk"; }
        }

        public override int BaseWeight {
            get { return -30; }
        }

        public override AffectIcon Icon {
            get { return AffectIcon.Berserk; }
        }

        public override void SetAffect() {
            base.SetAffect();
            LocalSummary.OnCreatureSummon += DoCreatureBerserk;
            LocalSummary.OnStartOffencePhase += DoBerserk;
            DoBerserk();
        }
        public override void ResetAffect() {
            base.ResetAffect();
            LocalSummary.OnCreatureSummon -= DoCreatureBerserk;
            LocalSummary.OnStartOffencePhase -= DoBerserk;
        }

        private void DoBerserk() {
            if (Owner is Creature) DoCreatureBerserk((Creature) Owner);
        }
        private void DoCreatureBerserk(Creature creature) {
            if (creature.Owner.IsCurrent && creature.Owner.State == PlayerState.Offence &&
                creature.State == CreatureState.Untapped && creature.CanAttack)
                creature.State = CreatureState.Offence;
        }
    }
}